package com.tian.controller.api;


import com.tian.common.CommonResult;
import com.tian.dto.CityInfoListRespDto;
import com.tian.dto.CityInfoRespDto;
import com.tian.service.CityInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * {@code @description:} 省市区县
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024-03-25 21:17
 * {@code @version:} 1.0
 */
@RestController
@RequestMapping("/user/city")
@Api(value = "城市信息接口",tags = "城市信息")
public class CityInfoController {
    @Resource
    private CityInfoService cityInfoService;

    @GetMapping("/list")
    @ApiOperation(value = "查询城市信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value="城市名称",required = true,dataType = "String"),
            @ApiImplicitParam(name="areaCode",value="城市编码",required = true,dataType = "String")
    })
    public CommonResult<CityInfoListRespDto> list(String name, String areaCode) {
        return cityInfoService.getCityInfoTree(name, areaCode);
    }
    @GetMapping("/list/areaCode/{id}")
    @ApiOperation(value = "查询某个省/下城市信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="areaCode",value="城市编码",required = true,dataType = "Integer")
    })
    public CommonResult<List<CityInfoRespDto>> listByAreaCode(@PathVariable("id") Integer id) {
        return cityInfoService.getChildCityListByAreaCode(id);
    }
    @GetMapping("/list/province")
    @ApiOperation(value = "查询所有省份信息列表")
    public CommonResult<List<CityInfoRespDto>> provinceCityList() {
        return cityInfoService.provinceCityList();
    }
}
